package org.bigjava.user.service.impl;

import org.bigjava.bean.Notice;
import org.bigjava.common.Constant;
import org.bigjava.user.mapper.AdminMapper;
import org.bigjava.user.mapper.UserFunctionMapper;
import org.bigjava.user.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Timestamp;
import java.util.Date;

@Service
public class AdminServiceImpl implements AdminService {
    java.util.Date date = new Date();//获取当前时间
    Timestamp t = new Timestamp(date.getTime());

    @Autowired
    AdminMapper adminMapper;
    @Autowired
    UserFunctionMapper userFunctionMapper;

    @Transactional
    @Override
    public void insertNotice(Notice notice) {
        notice.setNoticeDate(t);
        System.out.println(notice);
        adminMapper.insertNotice(notice);
    }

    @Transactional
    @Override
    public void updateNoticeState(long noticeState, long noticeId) {
        adminMapper.updateNoticeState(noticeState,noticeId);
    }

    @Override
    public void updateUserState(long userstate, long userId) {
        adminMapper.updateUserState(userstate,userId);
    }

    @Transactional
    @Override
    public void updateUserHead(long userId) {
        //修改用户头像为默认头像
        System.out.println(userId);
        userFunctionMapper.updateUserHead(Constant.defaulthead,userId);
    }

    @Transactional
    @Override
    public void updatePetName(long userId) {
        //修改用户昵称为违规昵称
        int num = (int) (Math.random()*1000);//设置随机数
        userFunctionMapper.updatePetName(Constant.defaultUnPetName+num,userId);

    }
}
